<template>
  <van-pull-refresh v-model="refreshing" :disabled="disabled" @refresh="onRefresh">
    <van-list v-model="loading" :finished="finished" :finished-text="finishedText" :immediate-check="immediateCheck"
              @load="onLoad">
      <slot></slot>
    </van-list>
  </van-pull-refresh>
</template>

<script>
export default {
  name: 'BaseList',
  model: {
    prop: 'loading'
  },
  props: {
    offset: {
      type: [Number, String],
      default: 300
    },
    loadingText: {
      type: String,
      default: '加载中...'
    },
    finishedText: {
      type: String,
      default: '没有更多了'
    },
    errorText: {
      type: String,
      default: '请求失败，点击重新加载'
    },
    immediateCheck: {
      type: Boolean,
      default: false
    },
    direction: {
      type: String,
      default: 'down'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      refreshing: false,
      loading: false,
      finished: false,
      error: false
    }
  },
  methods: {
    refresh () {
      this.refreshing = false
      this.loading = false
      this.finished = false
      this.error = false
    },
    onRefresh () {
      this.finished = false
      this.$emit('refresh')
    },
    onLoad () {
      this.$emit('load')
    },
    openLoad () {
      this.finished = false
    },
    forceUpdate (dirty) {
      if (dirty) {
        this.finished = true
      }
      this.refreshing = false
      this.loading = false
    }
  }
}
</script>
